The assignment for this week was to read a microcontroller data sheet and to program our board to do something, with as many different programming languages and programming environments as possible.
the embedded system is a combination of computer software and hardware designed for a specific function. Industrial machines, automobiles, medical equipment, cameras, household appliances, airplanes, vending machines and toys, as well as mobile devices, are possible locations for an embedded system.
To program an embedded system, we use embedded programming languages. These languages divided into; the assembly level programming languages, and the high level languages like C, Pascal, and COBOL.
These systems can only understand instructions writing in the machine language, which is mainly consist of ZEROs and ONEs. And since this language is very complex, a low-level assembly language was designed to represent various instructions in symbolic code and forms can be understood.
These low-level languages may be produced by compiling source code from a high-level programming language (such as C/C++) but can also be written from scratch.
The fundamental unit of computer storage is a bit; it could be ON (1) or OFF (0) and a group of 8 related bits makes a byte on most of the modern computers. An assembler is the program that reads the assembly language program, and produces the corresponding machine language back to the machine.
This week’s assignment divided into three parts, first is programming my FABISP I made weeks ago with an Arduino, second is programming my echo hello board using my ISP with Embedded C language, and third is programming input/output Devices board and my final Project board with Arduino language.
In the last weeks when I produced my first FABISP, I programmed it using Arduino in order to be able to use it as a programmer in the future. You can find All the steps and photos Here
I decided to use the embedded C programming to program my board to light the LED Red while the button pressed and Blue when it not pressed, as a simple start for me in the C language. and then when completing it I will upgrade the code
To be able to do that successfully, I needed to read some documents about the embedded programming and how it should be done for the AVR Microcontrollers. The first reference I used was my instructors’ Nadine site, where she documented in details how and why we do each step. The second was the this tutorial.
So, in order to be able to give your board orders, you have to do the following steps:
Since I used RGB LED in my echo Hello board, I decided to make it simple and write a simple code, as I mentioned I want it to light the LED Red while the button pressed and Blue when it not pressed.
I used this tutorial to learn the basics of the C language. Using the Arduino IDE I first initialized the required input/output avr library as well as the clock frequency of 20 Mhz.
Then defined the output and input ports for the LED and Button.
When I designed my Echo Hello board I didn’t add an input push button to the schematic. So, I decided for now to use a limit switch connected to the FTDI pins since Im not using them.
to set the pins numbers correctly, I used this illustration from the attiny44 datasheet to know the correct name for each pin.
The limit switch is very simple. it has 3 pins, 2 for the GND & VCC and the third the control pin.
below is my full code.
#include avr/io.h #include util/delay.h #define F_CPU20000UL #define red PA7 #define green PA6 #define blue PB2 #define Button PA1 // TX PIN from FTDI int main(void) { DDRA = 0b11000000; //DDRB = 0b00000100; while (1) { if (Button == 1){ PORTA = 0b1000000; //red high } else { PORTA = 0b01000000; // blue high } } }
I used this link to calculate the fuses, its simple calculator, you have to select your microcontroller and the clock you’ve used in your board. And from the datasheet you should know what should be checked (programmed (0)), and what should uncheck (unprogrammed (1)).
I used the datasheet with this tutorial to correctly set the fuses, the table in the tutorial tells you which page in the data sheet you have to look in to set the right value for each register.
The makefile basically is a text file has instructions for a specific project. It will be read and executed using the make command.
I used neil’s makefile. And edit it to suit my program. I changed the program name to match the C-Code , and deleted all unnecessary lines (kept the first 4 lines for configuring the Makefile and the two lines for program usbtiny and usbtiny fuses).
So, you can see my make file below.
This is the same step I did in programming my FABISP Here, but I repeated it since I used another PC.
The make command reads the make file, and creates a .hex & .out file from it.
So, after navigating the folder you created in your PC (that contains the makefile and the C-Code), this step should create a .hex & .out files .
When I operated this line, it gave me error because the Command 'make' not found, but it gave me a command to install it (sudo apt install make ) , and worked successfully.
yazan@YazanPC:~$ sudo apt-get install flex byacc bison gcc libusb-dev avrdude Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu cpp-9 gcc-10-base gcc-9 gcc-9-base libasan5 libatomic1 libbinutils libc-dev-bin libc6 libc6-dbg libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libfl-dev libfl2 libftdi1 libgcc-9-dev libgcc-s1 libgomp1 libhidapi-libusb0 libitm1 liblsan0 libquadmath0 libsigsegv2 libstdc++6 libtsan0 libubsan1 libusb-0.1-4 linux-libc-dev m4 manpages-dev Suggested packages: dfu-programmer avrdude-doc binutils-doc bison-doc gcc-9-locales build-essential flex-doc gcc-multilib make autoconf automake libtool gcc-doc gcc-9-multilib gcc-9-doc glibc-doc m4-doc The following NEW packages will be installed: avrdude binutils binutils-common binutils-x86-64-linux-gnu bison byacc flex gcc gcc-9 libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcrypt-dev libctf-nobfd0 libctf0 libfl-dev libfl2 libftdi1 libgcc-9-dev libhidapi-libusb0 libitm1 liblsan0 libquadmath0 libsigsegv2 libtsan0 libubsan1 libusb-0.1-4 libusb-dev linux-libc-dev m4 manpages-dev The following packages will be upgraded: cpp-9 gcc-10-base gcc-9-base libc6 libc6-dbg libcc1-0 libgcc-s1 libgomp1 libstdc++6 9 upgraded, 33 newly installed, 0 to remove and 251 not upgraded. Need to get 33.8 MB/38.5 MB of archives. After this operation, 98.2 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 binutils-common amd64 2.34-6ubuntu1 [207 kB] Get:2 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 libbinutils amd64 2.34-6ubuntu1 [474 kB] Get:3 http://security.ubuntu.com/ubuntu focal-security/main amd64 libgomp1 amd64 10.2.0-5ubuntu1~20.04 [102 kB] Get:4 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 libctf-nobfd0 amd64 2.34-6ubuntu1 [47.0 kB] Get:5 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 libctf0 amd64 2.34-6ubuntu1 [46.6 kB] Get:6 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 binutils-x86-64-linux-gnu amd64 2.34-6ubuntu1 [1,614 kB] Get:7 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 binutils amd64 2.34-6ubuntu1 [3,376 B] Get:8 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 gcc amd64 4:9.3.0-1ubuntu2 [5,208 B] Get:9 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 libcrypt-dev amd64 1:4.4.10-10ubuntu4 [104 kB] Get:10 cdrom://Ubuntu 20.04.1 LTS Focal Fossa - Release amd64 (20200731) focal/main amd64 manpages-dev all 5.05-1 [2,266 kB] Get:11 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6-dbg amd64 2.31-0ubuntu9.1 [5,672 kB] Get:12 http://security.ubuntu.com/ubuntu focal-security/main amd64 gcc-10-base amd64 10.2.0-5ubuntu1~20.04 [19.7 kB] Get:13 http://security.ubuntu.com/ubuntu focal-security/main amd64 libgcc-s1 amd64 10.2.0-5ubuntu1~20.04 [41.6 kB] Get:14 http://security.ubuntu.com/ubuntu focal-security/main amd64 libcc1-0 amd64 10.2.0-5ubuntu1~20.04 [41.1 kB] Get:15 http://security.ubuntu.com/ubuntu focal-security/main amd64 libstdc++6 amd64 10.2.0-5ubuntu1~20.04 [503 kB] Get:16 http://security.ubuntu.com/ubuntu focal-security/main amd64 cpp-9 amd64 9.3.0-17ubuntu1~20.04 [7,494 kB] Get:17 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6 amd64 2.31-0ubuntu9.1 [2,712 kB] Get:18 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libsigsegv2 amd64 2.12-2 [13.9 kB] Get:19 http://us.archive.ubuntu.com/ubuntu focal/main amd64 m4 amd64 1.4.18-4 [199 kB] Get:20 http://us.archive.ubuntu.com/ubuntu focal/main amd64 flex amd64 2.6.4-6.2 [317 kB] Get:21 http://us.archive.ubuntu.com/ubuntu focal/main amd64 bison amd64 2:3.5.1+dfsg-1 [657 kB] Get:22 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libc-dev-bin amd64 2.31-0ubuntu9.1 [71.7 kB] Get:23 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6-dev amd64 2.31-0ubuntu9.1 [2,519 kB] Get:24 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libfl2 amd64 2.6.4-6.2 [11.5 kB] Get:25 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libfl-dev amd64 2.6.4-6.2 [6,316 B] Get:26 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libusb-0.1-4 amd64 2:0.1.12-32 [17.4 kB] Get:27 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 libftdi1 amd64 0.20-4build8 [14.8 kB] Get:28 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libusb-dev amd64 2:0.1.12-32 [30.3 kB] Get:29 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 libhidapi-libusb0 amd64 0.9.0+dfsg-1 [14.5 kB] Get:30 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 avrdude amd64 6.3-20171130+svn1429-2 [316 kB] Get:31 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 byacc amd64 20140715-1build1 [61.3 kB] Get:32 http://security.ubuntu.com/ubuntu focal-security/main amd64 gcc-9-base amd64 9.3.0-17ubuntu1~20.04 [19.1 kB] Get:33 http://security.ubuntu.com/ubuntu focal-security/main amd64 libitm1 amd64 10.2.0-5ubuntu1~20.04 [26.4 kB] Get:34 http://security.ubuntu.com/ubuntu focal-security/main amd64 libatomic1 amd64 10.2.0-5ubuntu1~20.04 [9,300 B] Get:35 http://security.ubuntu.com/ubuntu focal-security/main amd64 libasan5 amd64 9.3.0-17ubuntu1~20.04 [394 kB] Get:36 http://security.ubuntu.com/ubuntu focal-security/main amd64 liblsan0 amd64 10.2.0-5ubuntu1~20.04 [144 kB] Get:37 http://security.ubuntu.com/ubuntu focal-security/main amd64 libtsan0 amd64 10.2.0-5ubuntu1~20.04 [320 kB] Get:38 http://security.ubuntu.com/ubuntu focal-security/main amd64 libubsan1 amd64 10.2.0-5ubuntu1~20.04 [136 kB] Get:39 http://security.ubuntu.com/ubuntu focal-security/main amd64 libquadmath0 amd64 10.2.0-5ubuntu1~20.04 [146 kB] Get:40 http://security.ubuntu.com/ubuntu focal-security/main amd64 libgcc-9-dev amd64 9.3.0-17ubuntu1~20.04 [2,360 kB] Get:41 http://security.ubuntu.com/ubuntu focal-security/main amd64 gcc-9 amd64 9.3.0-17ubuntu1~20.04 [8,241 kB] Get:42 http://security.ubuntu.com/ubuntu focal-security/main amd64 linux-libc-dev amd64 5.4.0-48.52 [1,138 kB] Fetched 33.8 MB in 22s (1,563 kB/s) Extracting templates from packages: 100% Preconfiguring packages ... (Reading database ... 187886 files and directories currently installed.) Preparing to unpack .../libc6-dbg_2.31-0ubuntu9.1_amd64.deb ... Unpacking libc6-dbg:amd64 (2.31-0ubuntu9.1) over (2.31-0ubuntu9) ... Preparing to unpack .../libgomp1_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libgomp1:amd64 (10.2.0-5ubuntu1~20.04) over (10-20200411-0ubuntu1) ... Preparing to unpack .../gcc-10-base_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking gcc-10-base:amd64 (10.2.0-5ubuntu1~20.04) over (10-20200411-0ubuntu1) ... Setting up gcc-10-base:amd64 (10.2.0-5ubuntu1~20.04) ... (Reading database ... 187886 files and directories currently installed.) Preparing to unpack .../libgcc-s1_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libgcc-s1:amd64 (10.2.0-5ubuntu1~20.04) over (10-20200411-0ubuntu1) ... Setting up libgcc-s1:amd64 (10.2.0-5ubuntu1~20.04) ... (Reading database ... 187886 files and directories currently installed.) Preparing to unpack .../libcc1-0_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libcc1-0:amd64 (10.2.0-5ubuntu1~20.04) over (10-20200411-0ubuntu1) ... Preparing to unpack .../libstdc++6_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libstdc++6:amd64 (10.2.0-5ubuntu1~20.04) over (10-20200411-0ubuntu1) ... Setting up libstdc++6:amd64 (10.2.0-5ubuntu1~20.04) ... (Reading database ... 187886 files and directories currently installed.) Preparing to unpack .../libc6_2.31-0ubuntu9.1_amd64.deb ... Unpacking libc6:amd64 (2.31-0ubuntu9.1) over (2.31-0ubuntu9) ... Setting up libc6:amd64 (2.31-0ubuntu9.1) ... Selecting previously unselected package libsigsegv2:amd64. (Reading database ... 187886 files and directories currently installed.) Preparing to unpack .../00-libsigsegv2_2.12-2_amd64.deb ... Unpacking libsigsegv2:amd64 (2.12-2) ... Selecting previously unselected package m4. Preparing to unpack .../01-m4_1.4.18-4_amd64.deb ... Unpacking m4 (1.4.18-4) ... Selecting previously unselected package flex. Preparing to unpack .../02-flex_2.6.4-6.2_amd64.deb ... Unpacking flex (2.6.4-6.2) ... Selecting previously unselected package binutils-common:amd64. Preparing to unpack .../03-binutils-common_2.34-6ubuntu1_amd64.deb ... Unpacking binutils-common:amd64 (2.34-6ubuntu1) ... Selecting previously unselected package libbinutils:amd64. Preparing to unpack .../04-libbinutils_2.34-6ubuntu1_amd64.deb ... Unpacking libbinutils:amd64 (2.34-6ubuntu1) ... Selecting previously unselected package libctf-nobfd0:amd64. Preparing to unpack .../05-libctf-nobfd0_2.34-6ubuntu1_amd64.deb ... Unpacking libctf-nobfd0:amd64 (2.34-6ubuntu1) ... Selecting previously unselected package libctf0:amd64. Preparing to unpack .../06-libctf0_2.34-6ubuntu1_amd64.deb ... Unpacking libctf0:amd64 (2.34-6ubuntu1) ... Selecting previously unselected package binutils-x86-64-linux-gnu. Preparing to unpack .../07-binutils-x86-64-linux-gnu_2.34-6ubuntu1_amd64.deb ... Unpacking binutils-x86-64-linux-gnu (2.34-6ubuntu1) ... Selecting previously unselected package binutils. Preparing to unpack .../08-binutils_2.34-6ubuntu1_amd64.deb ... Unpacking binutils (2.34-6ubuntu1) ... Selecting previously unselected package bison. Preparing to unpack .../09-bison_2%3a3.5.1+dfsg-1_amd64.deb ... Unpacking bison (2:3.5.1+dfsg-1) ... Preparing to unpack .../10-cpp-9_9.3.0-17ubuntu1~20.04_amd64.deb ... Unpacking cpp-9 (9.3.0-17ubuntu1~20.04) over (9.3.0-10ubuntu2) ... Preparing to unpack .../11-gcc-9-base_9.3.0-17ubuntu1~20.04_amd64.deb ... Unpacking gcc-9-base:amd64 (9.3.0-17ubuntu1~20.04) over (9.3.0-10ubuntu2) ... Selecting previously unselected package libitm1:amd64. Preparing to unpack .../12-libitm1_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libitm1:amd64 (10.2.0-5ubuntu1~20.04) ... Selecting previously unselected package libatomic1:amd64. Preparing to unpack .../13-libatomic1_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libatomic1:amd64 (10.2.0-5ubuntu1~20.04) ... Selecting previously unselected package libasan5:amd64. Preparing to unpack .../14-libasan5_9.3.0-17ubuntu1~20.04_amd64.deb ... Unpacking libasan5:amd64 (9.3.0-17ubuntu1~20.04) ... Selecting previously unselected package liblsan0:amd64. Preparing to unpack .../15-liblsan0_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking liblsan0:amd64 (10.2.0-5ubuntu1~20.04) ... Selecting previously unselected package libtsan0:amd64. Preparing to unpack .../16-libtsan0_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libtsan0:amd64 (10.2.0-5ubuntu1~20.04) ... Selecting previously unselected package libubsan1:amd64. Preparing to unpack .../17-libubsan1_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libubsan1:amd64 (10.2.0-5ubuntu1~20.04) ... Selecting previously unselected package libquadmath0:amd64. Preparing to unpack .../18-libquadmath0_10.2.0-5ubuntu1~20.04_amd64.deb ... Unpacking libquadmath0:amd64 (10.2.0-5ubuntu1~20.04) ... Selecting previously unselected package libgcc-9-dev:amd64. Preparing to unpack .../19-libgcc-9-dev_9.3.0-17ubuntu1~20.04_amd64.deb ... Unpacking libgcc-9-dev:amd64 (9.3.0-17ubuntu1~20.04) ... Selecting previously unselected package gcc-9. Preparing to unpack .../20-gcc-9_9.3.0-17ubuntu1~20.04_amd64.deb ... Unpacking gcc-9 (9.3.0-17ubuntu1~20.04) ... Selecting previously unselected package gcc. Preparing to unpack .../21-gcc_9.3.0-1ubuntu2_amd64.deb ... Unpacking gcc (4:9.3.0-1ubuntu2) ... Selecting previously unselected package libc-dev-bin. Preparing to unpack .../22-libc-dev-bin_2.31-0ubuntu9.1_amd64.deb ... Unpacking libc-dev-bin (2.31-0ubuntu9.1) ... Selecting previously unselected package linux-libc-dev:amd64. Preparing to unpack .../23-linux-libc-dev_5.4.0-48.52_amd64.deb ... Unpacking linux-libc-dev:amd64 (5.4.0-48.52) ... Selecting previously unselected package libcrypt-dev:amd64. Preparing to unpack .../24-libcrypt-dev_4.4.10-10ubuntu4_amd64.deb ... Unpacking libcrypt-dev:amd64 (1:4.4.10-10ubuntu4) ... Selecting previously unselected package libc6-dev:amd64. Preparing to unpack .../25-libc6-dev_2.31-0ubuntu9.1_amd64.deb ... Unpacking libc6-dev:amd64 (2.31-0ubuntu9.1) ... Selecting previously unselected package libfl2:amd64. Preparing to unpack .../26-libfl2_2.6.4-6.2_amd64.deb ... Unpacking libfl2:amd64 (2.6.4-6.2) ... Selecting previously unselected package libfl-dev:amd64. Preparing to unpack .../27-libfl-dev_2.6.4-6.2_amd64.deb ... Unpacking libfl-dev:amd64 (2.6.4-6.2) ... Selecting previously unselected package libusb-0.1-4:amd64. Preparing to unpack .../28-libusb-0.1-4_2%3a0.1.12-32_amd64.deb ... Unpacking libusb-0.1-4:amd64 (2:0.1.12-32) ... Selecting previously unselected package libftdi1:amd64. Preparing to unpack .../29-libftdi1_0.20-4build8_amd64.deb ... Unpacking libftdi1:amd64 (0.20-4build8) ... Selecting previously unselected package libusb-dev. Preparing to unpack .../30-libusb-dev_2%3a0.1.12-32_amd64.deb ... Unpacking libusb-dev (2:0.1.12-32) ... Selecting previously unselected package manpages-dev. Preparing to unpack .../31-manpages-dev_5.05-1_all.deb ... Unpacking manpages-dev (5.05-1) ... Selecting previously unselected package libhidapi-libusb0:amd64. Preparing to unpack .../32-libhidapi-libusb0_0.9.0+dfsg-1_amd64.deb ... Unpacking libhidapi-libusb0:amd64 (0.9.0+dfsg-1) ... Selecting previously unselected package avrdude. Preparing to unpack .../33-avrdude_6.3-20171130+svn1429-2_amd64.deb ... Unpacking avrdude (6.3-20171130+svn1429-2) ... Selecting previously unselected package byacc. Preparing to unpack .../34-byacc_20140715-1build1_amd64.deb ... Unpacking byacc (20140715-1build1) ... Setting up manpages-dev (5.05-1) ... Setting up binutils-common:amd64 (2.34-6ubuntu1) ... Setting up linux-libc-dev:amd64 (5.4.0-48.52) ... Setting up libctf-nobfd0:amd64 (2.34-6ubuntu1) ... Setting up libgomp1:amd64 (10.2.0-5ubuntu1~20.04) ... Setting up libusb-0.1-4:amd64 (2:0.1.12-32) ... Setting up libc6-dbg:amd64 (2.31-0ubuntu9.1) ... Setting up byacc (20140715-1build1) ... update-alternatives: using /usr/bin/byacc to provide /usr/bin/yacc (yacc) in auto mode Setting up libsigsegv2:amd64 (2.12-2) ... Setting up libquadmath0:amd64 (10.2.0-5ubuntu1~20.04) ... Setting up libatomic1:amd64 (10.2.0-5ubuntu1~20.04) ... Setting up libhidapi-libusb0:amd64 (0.9.0+dfsg-1) ... Setting up libfl2:amd64 (2.6.4-6.2) ... Setting up libubsan1:amd64 (10.2.0-5ubuntu1~20.04) ... Setting up libcrypt-dev:amd64 (1:4.4.10-10ubuntu4) ... Setting up libbinutils:amd64 (2.34-6ubuntu1) ... Setting up libc-dev-bin (2.31-0ubuntu9.1) ... Setting up libcc1-0:amd64 (10.2.0-5ubuntu1~20.04) ... Setting up liblsan0:amd64 (10.2.0-5ubuntu1~20.04) ... Setting up libitm1:amd64 (10.2.0-5ubuntu1~20.04) ... Setting up gcc-9-base:amd64 (9.3.0-17ubuntu1~20.04) ... Setting up libtsan0:amd64 (10.2.0-5ubuntu1~20.04) ... Setting up libctf0:amd64 (2.34-6ubuntu1) ... Setting up libftdi1:amd64 (0.20-4build8) ... Setting up m4 (1.4.18-4) ... Setting up libasan5:amd64 (9.3.0-17ubuntu1~20.04) ... Setting up bison (2:3.5.1+dfsg-1) ... update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode Setting up cpp-9 (9.3.0-17ubuntu1~20.04) ... Setting up libc6-dev:amd64 (2.31-0ubuntu9.1) ... Setting up binutils-x86-64-linux-gnu (2.34-6ubuntu1) ... Setting up flex (2.6.4-6.2) ... Setting up avrdude (6.3-20171130+svn1429-2) ... Setting up binutils (2.34-6ubuntu1) ... Setting up libusb-dev (2:0.1.12-32) ... Setting up libfl-dev:amd64 (2.6.4-6.2) ... Setting up libgcc-9-dev:amd64 (9.3.0-17ubuntu1~20.04) ... Setting up gcc-9 (9.3.0-17ubuntu1~20.04) ... Setting up gcc (4:9.3.0-1ubuntu2) ... Processing triggers for libc-bin (2.31-0ubuntu9) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for install-info (6.7.0.dfsg.2-5) ... yazan@YazanPC:~$ sudo apt-get install gcc-avr Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: binutils-avr Suggested packages: gcc-doc avr-libc The following NEW packages will be installed: binutils-avr gcc-avr 0 upgraded, 2 newly installed, 0 to remove and 251 not upgraded. Need to get 16.9 MB of archives. After this operation, 88.5 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 binutils-avr amd64 2.26.20160125+Atmel3.6.2-1 [1,484 kB] Get:2 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 gcc-avr amd64 1:5.4.0+Atmel3.6.1-2build1 [15.4 MB] Fetched 16.9 MB in 13s (1,252 kB/s) Selecting previously unselected package binutils-avr. (Reading database ... 192465 files and directories currently installed.) Preparing to unpack .../binutils-avr_2.26.20160125+Atmel3.6.2-1_amd64.deb ... Unpacking binutils-avr (2.26.20160125+Atmel3.6.2-1) ... Selecting previously unselected package gcc-avr. Preparing to unpack .../gcc-avr_1%3a5.4.0+Atmel3.6.1-2build1_amd64.deb ... Unpacking gcc-avr (1:5.4.0+Atmel3.6.1-2build1) ... Setting up binutils-avr (2.26.20160125+Atmel3.6.2-1) ... Setting up gcc-avr (1:5.4.0+Atmel3.6.1-2build1) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9) ... yazan@YazanPC:~$ sudo apt-get install avr-libc Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: avr-libc 0 upgraded, 1 newly installed, 0 to remove and 251 not upgraded. Need to get 4,854 kB of archives. After this operation, 43.2 MB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 avr-libc all 1:2.0.0+Atmel3.6.1-2 [4,854 kB] Fetched 4,854 kB in 4s (1,259 kB/s) Selecting previously unselected package avr-libc. (Reading database ... 193391 files and directories currently installed.) Preparing to unpack .../avr-libc_1%3a2.0.0+Atmel3.6.1-2_all.deb ... Unpacking avr-libc (1:2.0.0+Atmel3.6.1-2) ... Setting up avr-libc (1:2.0.0+Atmel3.6.1-2) ... Processing triggers for man-db (2.9.1-1) ... yazan@YazanPC:~$ sudo apt-get install libc6-dev Reading package lists... Done Building dependency tree Reading state information... Done libc6-dev is already the newest version (2.31-0ubuntu9.1). libc6-dev set to manually installed. 0 upgraded, 0 newly installed, 0 to remove and 251 not upgraded.
yazan@YazanPC:~/Desktop/myfiles$ make avr-objcopy -O ihex first.rgb.red.green.out first.rgb.red.green.c.hex;\ avr-size --mcu=attiny44 --format=avr first.rgb.red.green.out AVR Memory Usage ---------------- Device: attiny44 Program: 64 bytes (1.6% Full) (.text + .data + .bootloader) Data: 0 bytes (0.0% Full) (.data + .bss + .noinit) yazan@YazanPC:~/Desktop/myfiles$ make program-fabISP avr-objcopy -O ihex first.rgb.red.green.out first.rgb.red.green.c.hex;\ avr-size --mcu=attiny44 --format=avr first.rgb.red.green.out AVR Memory Usage ---------------- Device: attiny44 Program: 64 bytes (1.6% Full) (.text + .data + .bootloader) Data: 0 bytes (0.0% Full) (.data + .bss + .noinit) avrdude -p t44 -P usb -c usbtiny -U flash:w:first.rgb.red.green.c.hex avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.00s avrdude: Device signature = 0x1e9207 (probably t44) avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file "first.rgb.red.green.c.hex" avrdude: input file first.rgb.red.green.c.hex auto detected as Intel Hex avrdude: writing flash (64 bytes): Writing | ################################################## | 100% 0.06s avrdude: 64 bytes of flash written avrdude: verifying flash memory against first.rgb.red.green.c.hex: avrdude: load data flash data from input file first.rgb.red.green.c.hex: avrdude: input file first.rgb.red.green.c.hex auto detected as Intel Hex avrdude: input file first.rgb.red.green.c.hex contains 64 bytes avrdude: reading on-chip flash data: Reading | ################################################## | 100% 0.07s avrdude: verifying ... avrdude: 64 bytes of flash verified avrdude: safemode: Fuses OK (E:FF, H:DF, L:E2) avrdude done. Thank you. yazan@YazanPC:~/Desktop/myfiles$
After finishing all the steps, I decided to write more complex code. Below you can see the new code and the video.
#include avr/io.h> #include util/delay.h> #include time.h> #define F_CPU20000UL #define red PA7 #define green PA6 //#define blue PB2 #define Button PA1 // TX PIN int main(void) { DDRA = 0b11000000; //DDRB = 0b00000100; while (1) { if (Button == 1){ PORTA = 0b1000000; delay (500); PORTA = 0b0100000; delay (500); } else { PORTA = 0b11000000; delay (500); PORTA = 0b00000000; delay (500); } } }
Arduino language is a combination of C/C++, it’s a simple way to program your board without the need to enter to the microcontroller’s registers each time you type a command. Its design to be easy for beginner users and advanced enough for advanced users.
I used this language multiple times during this course. like when I programmed the input devices board to control the DC rotation direction depending on the touch sensor HERE, and when I programmed my final project board to light up each country area depending on the selected country in the mobile application HERE.